<?php
/**
 * Created by PhpStorm OF Administrator.
 * User: YUYI
 * Date: 2018/7/18 0018
 * Time: 上午 9:26
 * Administrator
 */

namespace app\api\controller;


use app\common\model\UserEquipments;
use app\common\model\Users;
use app\common\util\ReturnMsgUtil;
use think\Controller;
use think\Request;

class Base extends Controller
{
    use ReturnMsgUtil;
    /**
     * @var null|Users
     */
    protected $user;

    /**
     * @var null|UserEquipments
     */
    protected $ue;

    public function _initialize(Request $request = null)
    {
        $eid = input('user_id');
        $uid = input('uid');
        if ((!$eid || $eid == 'voundefined')&&(!$uid || $uid == 'undefined')){
            exit($this->errorInfo('无效用户'));
        }
        $this->ue = UserEquipments::get(['equipment_id'=>$eid]);
        $this->user = Users::get($this->ue?$this->ue->user_id:$uid);
        if (!$this->ue && !$this->user){
            exit($this->errorInfo('无此用户'));
        }
        if (!$this->request->isAjax() && !$_FILES){
            exit($this->errorInfo('非法访问'));
        }
    }
}